package com.lzc.zhxy.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lzc.zhxy.mapper.TbGradeMapper;
import com.lzc.zhxy.pojo.TbGrade;
import com.lzc.zhxy.service.TbGradeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author 82389
 * @description 针对表【tb_grade】的数据库操作Service实现
 * @createDate 2022-04-16 18:00:37
 */
@Service("tbGradeService")
@Transactional
public class TbGradeServiceImpl extends ServiceImpl<TbGradeMapper, TbGrade> implements TbGradeService {

    /**
     * 分页查询模糊查询
     *
     * @param pageParam
     * @param gradeName
     * @return
     */
    @Override
    public IPage<TbGrade> getGradeByOpr(Page<TbGrade> pageParam, String gradeName) {
        QueryWrapper<TbGrade> queryWrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(gradeName)) {
            queryWrapper.like("name", gradeName);
        }
        //设置排序
        queryWrapper.orderByDesc("id");
        queryWrapper.orderByAsc("name");
        //分页查询数据
        Page<TbGrade> page = baseMapper.selectPage(pageParam, queryWrapper);
        return page;
    }

    /**
     * 获取所有Grade信息
     * @return
     */
    @Override
    public List<TbGrade> getGrade() {
        List<TbGrade> grades = baseMapper.selectList(null);
        return grades;
    }

}
